var sweatShopStores = {
   userStatusStore : new Ext.data.JsonStore({
        url: 'User/getStatuses'
        , autoLoad : true
        , storeId : 'statusStoreForCombo'
        ,root: 'data'
        ,idProperty: 'userStatusId'
        ,fields: [
            'userStatusId'
            , 'text'
        ]
    })
   ,userGroupStore : new Ext.data.JsonStore({
        url: 'User/getGroups'
        , autoLoad : true
        , storeId : 'groupStoreForCombo'
        ,root: 'data'
        ,idProperty: 'userGroupId'
        ,fields: [
            'userGroupId'
            , 'text'
        ]
    })
   ,assigneeStore : new Ext.data.JsonStore({
        url: 'User/getAssignees'
        , storeId : 'assigneeStoreForCombo'
        ,root: 'data'
        ,idProperty: 'userId'
        ,fields: [
            'userId'
            , 'username'
        ]
    })
    ,productStore : new Ext.data.JsonStore({
        url: 'Product/getProducts'
        , storeId : 'productStoreForCombo'
        ,root: 'data'
        ,idProperty: 'productId'
        ,fields: [
            'productId'
            , 'product'
        ]
    })
    ,sprintStore : new Ext.data.JsonStore({
        url: 'Sprint/getSprints'
        ,storeId : 'sprintStore'
        ,baseParams :{
            showPast : true
        }
        ,sortInfo : {
            field : 'sprint'
            ,direction : 'DESC'
        }
        ,root: 'data'
        ,idProperty: 'sprint'
        ,fields: [
            'sprint'
            , 'name'
            , 'startDate'
            , 'endDate'
        ]
        ,autoLoad: true
    })
    ,openSprintStore : new Ext.data.JsonStore({
        url: 'Sprint/getOpenSprints'
        ,storeId : 'openSprintStore'
        ,root: 'data'
        ,idProperty: 'sprint'
        ,fields: [
            'sprint'
            , 'name'
        ]
        ,autoLoad: true
    })
    , userCrudStore : new Ext.data.JsonStore({
        storeId: 'userCrudStore'
        ,proxy: new Ext.data.HttpProxy({
            api: {
                read : 'User/load',
                create : 'User/add',
                update: 'User/update',
                destroy: 'User/delete'
            }
        })
        ,writer : new Ext.data.JsonWriter({
            writeAllFields: true
            ,listful: false
        })
        ,batch : false
        ,autoSave: false
        ,root: 'data'
        ,idProperty: 'id'
        ,messageProperty: 'message'
        ,fields: [
            'id'
            , 'username'
            , 'email'
            , 'userGroupId'
            , 'userStatusId'
            , 'password'
            , 'password2'
        ]
        ,listeners : {
            write : function(store,action,result,transaction,record)
            {
                globals.storeWriteListener(store, action, result, transaction, record);
            }
            ,exception : function(Proxy, type, action, options, response, arg)
            {
                console.log('Exception:',Proxy, type, action, options, response, arg);
                sweatShop.log(response.message, response.success ? 1 : 4);
            }
        }
    })
    , productCrudStore : new Ext.data.JsonStore({
        storeId: 'productCrudStore'
        ,proxy: new Ext.data.HttpProxy({
            api: {
                read : 'Product/load',
                create : 'Product/add',
                update: 'Product/update',
                destroy: 'Product/delete'
            }
        })
        ,writer : new Ext.data.JsonWriter({
            writeAllFields: true
            ,listful: true
        })
        ,autoSave: true
        ,root: 'data'
        ,idProperty: 'productId'
        ,fields: [
            'productId'
            , 'product'
        ]
    })
}

productCombo = Ext.extend(Ext.form.ComboBox, {
     store : 'productStoreForCombo'
    , mode : 'remote'
    , autoSelect : true
    , forceSelection : true
    , selectOnFocus : true
    , submitValue : false
    , displayField : 'product'
    , valueField : 'productId'
    , minChars : 2
    , triggerAction: 'all'
    , lazyInit : false
});
Ext.reg('productcombo', productCombo);

assigneeCombo = Ext.extend(Ext.form.ComboBox, {
     store : 'assigneeStoreForCombo'
    , mode : 'remote'
    , autoSelect : true
    , forceSelection : true
    , selectOnFocus : true
    , submitValue : false
    , displayField : 'username'
    , valueField : 'userId'
    , minChars : 2
    , triggerAction: 'all'
    , lazyInit : false
});
Ext.reg('assigneecombo', assigneeCombo);

statusCombo = Ext.extend(Ext.form.ComboBox, {
     store : 'statusStoreForCombo'
    , mode : 'local'
    , autoSelect : true
    , forceSelection : true
    , selectOnFocus : true
    , submitValue : false
    , displayField : 'text'
    , valueField : 'userStatusId'
    , minChars : 2
    , triggerAction: 'all'
    , lazyInit : false
});
Ext.reg('statuscombo', statusCombo);

groupCombo = Ext.extend(Ext.form.ComboBox, {
     store : 'groupStoreForCombo'
    , mode : 'local'
    , autoSelect : true
    , forceSelection : true
    , selectOnFocus : true
    , submitValue : false
    , displayField : 'text'
    , valueField : 'userGroupId'
    , minChars : 2
    , triggerAction: 'all'
    , lazyInit : false
});
Ext.reg('groupcombo', groupCombo);

sprintCombo = Ext.extend(Ext.form.ComboBox, {
     store : 'sprintStore'
    , mode : 'local'
    , autoSelect : true
    , forceSelection : true
    , selectOnFocus : true
    , submitValue : false
    , displayField : 'name'
    , valueField : 'sprint'
    , minChars : 1
    , triggerAction: 'all'
    , lazyInit : false
    , disablePreselect : false
    , initComponent : function()
    {
        sprintCombo.superclass.initComponent.call(this);
        if(!this.disablePreselect)
            this.on('afterrender', this.queryPreselection)
    }
    , queryPreselection : function()
    {
        Ext.Ajax.request({
            url: 'Sprint/getCurrent'
            ,success: this.preselectValue
            ,failure : globals.formSubmitFailed
            ,scope : this
        })
    }
    , preselectValue : function(response, request)
    {
        var result = Ext.util.JSON.decode(response.responseText);
        this.setValue(result.sprint);
        sweatShop.currentSprint = result.sprint;
    }
});
Ext.reg('sprintcombo', sprintCombo);

openSprintCombo = Ext.extend(sprintCombo, {
    store : 'openSprintStore'
    ,disablePreselect : true
})
Ext.reg('opensprintcombo', openSprintCombo);
